package com.bigdata.service.controller.app;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bigdata.common.annotation.Log;
import com.bigdata.common.annotation.RepeatSubmit;
import com.bigdata.common.core.controller.BaseController;
import com.bigdata.common.core.domain.PageQuery;
import com.bigdata.common.core.domain.R;
import com.bigdata.common.core.page.TableDataInfo;
import com.bigdata.common.core.validate.AddGroup;
import com.bigdata.common.core.validate.EditGroup;
import com.bigdata.common.enums.BusinessType;
import com.bigdata.common.utils.poi.ExcelUtil;
import com.bigdata.service.domain.bo.DatasetTagsBo;
import com.bigdata.service.domain.vo.DatasetTagsVo;
import com.bigdata.service.service.IDatasetTagsService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 数据集-标签关联
 *
 * @author ruoyi
 * @date 2025-07-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/service/datasetTags")
public class AppDatasetTagsController extends BaseController {

    private final IDatasetTagsService iDatasetTagsService;

    /**
     * 查询数据集-标签关联列表
     */
    @SaCheckPermission("service:tags:list")
    @GetMapping("/list")
    public TableDataInfo<DatasetTagsVo> list(DatasetTagsBo bo, PageQuery pageQuery) {
        return iDatasetTagsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出数据集-标签关联列表
     */
    @SaCheckPermission("service:tags:export")
    @Log(title = "数据集-标签关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DatasetTagsBo bo, HttpServletResponse response) {
        List<DatasetTagsVo> list = iDatasetTagsService.queryList(bo);
        ExcelUtil.exportExcel(list, "数据集-标签关联", DatasetTagsVo.class, response);
    }

    /**
     * 获取数据集-标签关联详细信息
     *
     * @param datasetId 主键
     */
    @SaCheckPermission("service:tags:query")
    @GetMapping("/{datasetId}")
    public R<DatasetTagsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String datasetId) {
        return R.ok(iDatasetTagsService.queryById(datasetId));
    }

    /**
     * 新增数据集-标签关联
     */
    @SaCheckPermission("service:tags:add")
    @Log(title = "数据集-标签关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DatasetTagsBo bo) {
        return toAjax(iDatasetTagsService.insertByBo(bo));
    }

    /**
     * 修改数据集-标签关联
     */
    @SaCheckPermission("service:tags:edit")
    @Log(title = "数据集-标签关联", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DatasetTagsBo bo) {
        return toAjax(iDatasetTagsService.updateByBo(bo));
    }

    /**
     * 删除数据集-标签关联
     *
     * @param datasetIds 主键串
     */
    @SaCheckPermission("service:tags:remove")
    @Log(title = "数据集-标签关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{datasetIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] datasetIds) {
        return toAjax(iDatasetTagsService.deleteWithValidByIds(Arrays.asList(datasetIds), true));
    }
}
